﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Control.conexion;

namespace Control.clases
{
    public class clsMarca
    {
        private int idMarca;
        private int marcaDescripcion;
        private string marcaSiglas;
        private string paginaweb;

        public System.Data.DataTable listarMarca()
        {
            clsConexion oDataBase = new clsConexion();
            try
            {
                DbCommand cmd = oDataBase.CargarComandoSP("USP_S_LISTAR_TB_MARCA");
                return oDataBase.EjecutarConsulta(cmd);
            }
            catch (Exception ex)
            {
                throw new System.Exception(ex.Message, ex.InnerException);
            }
        }

        public System.Data.DataTable buscarMarca(string _Id)
        {
            clsConexion oDataBase = new clsConexion();
            try
            {
                DbCommand cmd = oDataBase.CargarComandoSP("USP_S_BUSCAR_TB_MARCA");
                oDataBase.AddParametro(cmd, "@id_marca", _Id);

                return oDataBase.EjecutarConsulta(cmd);
            }
            catch (Exception ex)
            {
                throw new System.Exception(ex.Message, ex.InnerException);
            }
        }

        public int agregarMarca(string _Descripcion, string _Siglas, string _PaginaWeb)
        {
            try
            {
                clsConexion oDataBase = new clsConexion();
                int iReturn;
                DbCommand cmd = oDataBase.CargarComandoSP("USP_I_INSERTAR_TB_MARCA"); // insertar SP_INSERTAR

                // Ingresar parametros
                oDataBase.AddParametro(cmd, "@marca_sigla", _Siglas);
                oDataBase.AddParametro(cmd, "@marca_descripcion", _Descripcion);
                oDataBase.AddParametro(cmd, "@marca_pagina_web", _PaginaWeb);

                iReturn = oDataBase.EjecutarTransaccion(cmd);
                return iReturn;
            }
            catch (Exception ex)
            {
                throw new System.Exception(ex.Message, ex.InnerException);
            }
        }

        public int actualizarMarca(string _Id, string _Descripcion, string _Siglas, string _PaginaWeb)
        {
            try
            {
                clsConexion oDataBase = new clsConexion();
                int iReturn;
                DbCommand cmd = oDataBase.CargarComandoSP("USP_U_ACTUALIZAR_TB_MARCA"); // insertar SP_INSERTAR

                // Ingresar parametros
                oDataBase.AddParametro(cmd, "@id_marca", _Id);
                oDataBase.AddParametro(cmd, "@marca_sigla", _Siglas);
                oDataBase.AddParametro(cmd, "@marca_descripcion", _Descripcion);
                oDataBase.AddParametro(cmd, "@marca_pagina_web", _PaginaWeb);

                iReturn = oDataBase.EjecutarTransaccion(cmd);
                return iReturn;
            }
            catch (Exception ex)
            {
                throw new System.Exception(ex.Message, ex.InnerException);
            }
        }

        public int eliminarMarca(string _Id)
        {
            try
            {
                clsConexion oDataBase = new clsConexion();
                int iReturn;
                DbCommand cmd = oDataBase.CargarComandoSP("USP_D_ELIMINAR_TB_MARCA"); // insertar SP_INSERTAR

                // Ingresar parametros
                oDataBase.AddParametro(cmd, "@id_marca", _Id);

                iReturn = oDataBase.EjecutarTransaccion(cmd);
                return iReturn;
            }
            catch (Exception ex)
            {
                throw new System.Exception(ex.Message, ex.InnerException);
            }
        }
    }
}
